<template>
  <header class="header">
    <h1>todos</h1>
    <input id="toggle-all" class="toggle-all" type="checkbox" v-model="isAll">
    <label for="toggle-all"></label>
    <input
      class="new-todo"
      placeholder="输入任务名称-回车确认"
      autofocus
      v-model.trim="value"
      @keydown.enter="addList(value)"
    />
  </header>
</template>

<script>
export default {
  data() {
    return{
      value:''
    }
  },
  computed:{
    list() {
      return this.$store.state.todomain.list
    },
    isAll:{
      get() {
        return this.list.every(item => item.isDone)
    },
      set(val) {
        return this.changIsAll(val)
    }
    }
  },
  methods: {
    addList(value) {
      if(value !== ''){
        this.$store.commit('todomain/addList',value)
        this.value = ''
      } 
    },
    changIsAll(val) {
      this.$store.commit('todomain/changIsAll',val)
    }
  }
}
</script>
